// pages/address/address.js
var usedata = require("../addressdata/addressdata.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address:"",
    addressSelect:"",
    addressText:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      address: usedata.address,
      addressText: usedata.address[0].addressVal,      
    })
    console.log(this.data.addressText)
  },
  addressRadio: function (e) {//选择地址
    console.log('radio发生change事件，携带的value值为：', e.detail.value)
    this.setData({
      addressText: e.detail.value
    })
  },
  remove: function (e) {
    // 删除
    var count = this.data.address;
    var that = this;
    var mrAddress = that.data.addressText
    wx.showModal({
      title: '提示',
      content: '确认删除吗？',
      success: function (res) {
        if (res.confirm) {
          // console.log('用户点击确定')
          // 获取要删除数据的id 
          var index = e.currentTarget.dataset.index;
          // 删除数组对应的数据内容 
          var release = count;
          // 获取选中的radio索引
          count.splice(index, 1)
          //判断数据的长度 
          var len = count.length;
          //通过判断数组的长度来决定是否显示隐藏的部分 
          // console.log(count)
          that.setData({
            address: count
          });
        } else if (res.cancel) {
          console.log('用户点击取消删除')
        }
      }

    })
  },
  goEditAddressId: function (event) {
    var newsid = event.currentTarget.dataset.newsid;
    wx.navigateTo({
      url: '../editAddress/editAddress?newsid=' + newsid
      // 跳转到商品详情
    })
  },
  goEditAddress: function () {//跳转地址页面
    wx.navigateTo({
      url: '../editAddress/editAddress'
    })
  },
})